import { IPSDataEntity } from '../dataentity/ipsdata-entity';
import { IPSDEDataSet } from '../dataentity/ds/ipsdedata-set';
import { IPSSysUserRole } from './ipssys-user-role';
import { IPSSysUserRoleData } from './ipssys-user-role-data';
import { IPSSysUserRoleRes } from './ipssys-user-role-res';
import { IPSSystemModule } from '../system/ipssystem-module';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSysUserRoleImpl extends PSModelObjectImpl implements IPSSysUserRole {
  get codeName(): string {
    return this.M.codeName;
  }

  get defaultUser(): 'NONE' | 'ACCESSUSER' | 'ACCESSADMIN' | 'USER' | 'ADMIN' {
    return this.M.defaultUser || 'NONE';
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected psdedataset: IPSDEDataSet | null = null;

  getPSDEDataSet(): IPSDEDataSet | null {
    if (this.psdedataset != null) return this.psdedataset;
    const value = this.M.getPSDEDataSet;
    if (value == null) {
      return null;
    }
    this.psdedataset = this.getPSDataEntityMust().findPSDEDataSet(value);
    return this.psdedataset;
  }

  get psDEDataSet(): IPSDEDataSet | null {
    return this.getPSDEDataSet();
  }

  getPSDEDataSetMust(): IPSDEDataSet {
    const value = this.getPSDEDataSet();
    if (value == null) {
      throw new Error('未指定实体数据集对象');
    }
    return value;
  }

  protected psdataentity: IPSDataEntity | null = null;

  getPSDataEntity(): IPSDataEntity | null {
    if (this.psdataentity != null) return this.psdataentity;
    const value = this.M.getPSDataEntity;
    if (value == null) {
      return null;
    }
    this.psdataentity = this.getPSModel4('dataentity.IPSDataEntity', value, 'getPSDataEntity') as IPSDataEntity;
    return this.psdataentity;
  }

  get psDataEntity(): IPSDataEntity | null {
    return this.getPSDataEntity();
  }

  getPSDataEntityMust(): IPSDataEntity {
    const value = this.getPSDataEntity();
    if (value == null) {
      throw new Error('未指定实体对象');
    }
    return value;
  }

  protected pssysuserroledatas: IPSSysUserRoleData[] | null = null;

  getPSSysUserRoleDatas(): IPSSysUserRoleData[] | null {
    if (this.pssysuserroledatas == null) {
      this.pssysuserroledatas = this.fillChildListModel(this.M.getPSSysUserRoleDatas, 'security.IPSSysUserRoleData') as IPSSysUserRoleData[];
    }
    return this.pssysuserroledatas;
  }

  get psSysUserRoleDatas(): IPSSysUserRoleData[] | null {
    return this.getPSSysUserRoleDatas();
  }

  findPSSysUserRoleData(objKey: any): IPSSysUserRoleData | null {
    return this.getPSModel5('security.IPSSysUserRoleData', this.getPSSysUserRoleDatas(), objKey) as IPSSysUserRoleData;
  }

  protected pssysuserrolereses: IPSSysUserRoleRes[] | null = null;

  getPSSysUserRoleReses(): IPSSysUserRoleRes[] | null {
    if (this.pssysuserrolereses == null) {
      this.pssysuserrolereses = this.fillChildListModel(this.M.getPSSysUserRoleReses, 'security.IPSSysUserRoleRes') as IPSSysUserRoleRes[];
    }
    return this.pssysuserrolereses;
  }

  get psSysUserRoleReses(): IPSSysUserRoleRes[] | null {
    return this.getPSSysUserRoleReses();
  }

  findPSSysUserRoleRes(objKey: any): IPSSysUserRoleRes | null {
    return this.getPSModel5('security.IPSSysUserRoleRes', this.getPSSysUserRoleReses(), objKey) as IPSSysUserRoleRes;
  }

  protected pssystemmodule: IPSSystemModule | null = null;

  getPSSystemModule(): IPSSystemModule | null {
    if (this.pssystemmodule != null) return this.pssystemmodule;
    const value = this.M.getPSSystemModule;
    if (value == null) {
      return null;
    }
    this.pssystemmodule = this.getPSModel4('system.IPSSystemModule', value, 'getPSSystemModule') as IPSSystemModule;
    return this.pssystemmodule;
  }

  get psSystemModule(): IPSSystemModule | null {
    return this.getPSSystemModule();
  }

  getPSSystemModuleMust(): IPSSystemModule {
    const value = this.getPSSystemModule();
    if (value == null) {
      throw new Error('未指定系统模块');
    }
    return value;
  }

  get roleTag(): string {
    return this.M.roleTag;
  }

  get roleType(): 'CUSTOM' | 'DEDATASET' {
    return this.M.roleType;
  }

  protected unirestags: string[] | null = null;

  getUniResTags(): string[] | null {
    if (this.unirestags == null) {
      const value = this.M.uniResTags;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this.unirestags = list;
    }
    return this.unirestags.length == 0 ? null : this.unirestags;
  }

  get uniResTags(): string[] | null {
    return this.getUniResTags();
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get globalRole(): boolean {
    return this.M.globalRole != null ? this.M.globalRole : false;
  }

  get systemReserved(): boolean {
    return this.M.systemReserved != null ? this.M.systemReserved : false;
  }

  get cls(): string {
    return 'PSSysUserRoleImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelObject' || cls == 'IPSObject' || cls == 'security.IPSSysUserRole') return true;
    return super.instanceof(cls);
  }
}
